home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Hyper Stacks 1994 May
/
Hyper Stacks (Pacific HiTech)(1994)[Mac].iso
/
XCMDS&XFCNS
/
USING APPS AS XCMDs
/
xxcmd_shell.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-06-30
|
3KB
|
144 lines
#include <Types.h>
#include <Memory.h>
#include <OSUtils.h>
#include <SegLoad.h>
#include <Resources.h>
#include <Files.h>
#include <HyperXCmd.h>
#include "HyperXXCmd.h"
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#define ERIK 0x4552494B
static short cur_res_wd;
static int argc;
static char *argv[16];
main()
{
Str255 apName;
short apRefNum;
Handle apParam;
Size hsize;
XXCmdPtr xdata;
int xxcmd_setup();
short vol;
/* make sure that the application is being called by XXCMD */
GetAppParms(apName, &apRefNum, &apParam);
hsize = GetHandleSize(apParam);
xdata = (XXCmdPtr) *apParam;
if ((hsize == sizeof(XXCmdBlock)) &&
(xdata->message == 0) &&
(xdata->count == 0) &&
(xdata->sig == 0x87654321)) {
/* make all subsequent calls start with xxcmd_setup() */
xdata->nextpc = xxcmd_setup;
/* set the current directory so that files will be found in a resonable place */
xxcmd_get_wd();
GetVol(nil, &vol);
SetVol(nil, cur_res_wd);
/* call the initialization routine */
xxcmd_init();
SetVol(nil, vol);
/* do the normal processing */
xxcmd_setup();
}
}
xxcmd_get_wd()
{
FCBPBRec fcb;
WDPBRec wd;
OSErr s;
/* create a working directory for the directory of the current resource file. in */
/* HyperCard the current resource file will be the current stack. */
fcb.ioCompletion = nil;
fcb.ioNamePtr = nil;
fcb.ioVRefNum = 0;
fcb.ioRefNum = CurResFile();
fcb.ioFCBIndx = 0;
if ((s = PBGetFCBInfo(&fcb, false)) == noErr) {
wd.ioCompletion = nil;
wd.ioNamePtr = nil;
wd.ioVRefNum = fcb.ioFCBVRefNum;
wd.ioWDProcID = ERIK;
wd.ioWDDirID = fcb.ioFCBParID;
if ((s = PBOpenWD(&wd, false)) == noErr) {
cur_res_wd = wd.ioVRefNum;
} else {
cur_res_wd = 0;
}
} else {
cur_res_wd = 0;
}
}
xxcmd_setup()
{
Str255 apName;
short apRefNum, vol;
Handle apParam, h;
XCmdPtr paramPtr;
char *p, *xxcmd_dispatch();
int i;
/* set up the parameters to the XXCMD */
GetAppParms(apName, &apRefNum, &apParam);
paramPtr = ((XXCmdPtr) *apParam)->paramPtr;
argc = paramPtr->paramCount;
for (i = 0; i < argc; i++) {
HLock(paramPtr->params[i]);
argv[i] = *(paramPtr->params[i]);
}
/* set up the current directory */
GetVol(nil, &vol);
SetVol(nil, cur_res_wd);
/* call the processing routine */
p = xxcmd_dispatch(argc, argv);
/* clean up */
SetVol(nil, vol);
for (i = 0; i < argc; i++) {
if (argv[i] != NULL) {
HUnlock(paramPtr->params[i]);
}
}
/* set up the return value */
if (p != NULL) {
if (PtrToHand(p, &h, strlen(p) + 1) == noErr) {
paramPtr->returnValue = h;
} else {
p = "ERROR: out of memory.";
if (PtrToHand(p, &h, strlen(p) + 1) == noErr) {
paramPtr->returnValue = h;
}
}
}
}